import os
import subprocess
import pybythec
import pybythec.command_line
from pybythec import utils
from pybythec.utils import PybythecError
import json

libpath = os.path.join('C:' + os.path.sep, 'Users', 'X', 'Libs')


def main():
    protoc = os.path.join(libpath, 'bin', 'protoc')
    subprocess.run([protoc, '--cpp_out', '.', 'person.proto'])
    # homeDirPath = os.path.expanduser('~')
    # globalConfigPath = homeDirPath + '/.pybythecGlobals.json'
    # with open(globalConfigPath, 'r') as rf:
    #     globalConfig = json.load(rf)
    projConfig = {'showCompilerCmds': True, 'showLinkerCmds': True}
    localConfig = {
        'target': 'Simple',
        'binaryType': 'exe',
        'sources': ['main.cpp'],
        'installPath': '.'
    }
    localConfig['buildType'] = 'debug'
    localConfig['sources'].append('person.pb.cc')
    localConfig['incPaths'] = [os.path.join(libpath, 'include')]
    localConfig['libPaths'] = [os.path.join(libpath, 'bin'), os.path.join(libpath, 'lib')]
    localConfig['libs'] = ['libprotobufd']
    be = pybythec.getBuildElements(projConfig=projConfig,
                                   localConfig=localConfig)
    pybythec.build(be)


if __name__ == '__main__':
    main()
